import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Index',
    component: () => import('../views/Index.vue'),
    redirect: '/home',
    children: [
      {
        path: '/home',
        name: 'Home',
        meta: { title: 'Home' },
        component: () => import('../views/Home.vue'),
      },
      {
        path: '/product',
        name: 'Product',
        meta: { title: 'Product' },
        component: () => import('../views/Product.vue')
      },{
        path: '/service',
        name: 'Service',
        meta: { title: 'Service' },
        component: () => import('../views/Service.vue')
      },
      {
        path: '/about',
        name: 'About',
        meta: { title: 'About' },
        component: () => import('../views/About.vue')
      }
    ]
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  document.title = to.meta.title;
  next();
})

export default router
